package com.hgd.security.evp.swagger.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.classmate.ResolvedType;
import com.google.common.base.Optional;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.hgd.security.evp.swagger.entity.TestEntity;
import com.hgd.security.evp.swagger.util.SpringContextUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.schema.Example;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.schema.ModelReference;
import springfox.documentation.service.*;
import springfox.documentation.spring.web.DocumentationCache;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author ：尚村山夫
 * @date ：Created in 2019/8/13 22:39
 * @modified By：
 */
@RestController
@RequestMapping("test")
//@Api(tags = "测试Controller")
public class TestController {

    @PostMapping("/test01/{id}")
    @ApiOperation("测试01")
    public TestEntity test01(
        @RequestBody TestEntity testEntity
    ){
        TestEntity jsonObject=new TestEntity();
        jsonObject.setName("wangkaige");
        jsonObject.setId(1);
        DocumentationCache beanByClassType4 = SpringContextUtil.getBeanByClassType(DocumentationCache.class);



        Documentation aDefault = beanByClassType4.documentationByGroup("default");

        Multimap<String, ApiListing> apiListings = aDefault.getApiListings();
        Collection<ApiListing> apiListings1 = apiListings.get("test-controller");
        for (ApiListing apiListing : apiListings1) {
            List<ApiDescription> apis = apiListing.getApis();
            for (ApiDescription api : apis) {
                List<Operation> operations = api.getOperations();
                for (Operation operation : operations) {
                    List<Parameter> parameters = operation.getParameters();
                    /*
                    String name,
      String description,
      String defaultValue,
      boolean required,
      boolean allowMultiple,
      Boolean allowEmptyValue,
      ModelReference modelRef,
      Optional<ResolvedType> type,
      AllowableValues allowableValues,
      String paramType,
      String paramAccess,
      boolean hidden,
      String pattern,
      String collectionFormat,
      int order,
      Object scalarExample,
      Multimap<String, Example> examples,
      List<VendorExtension> vendorExtensions
                     */
                    ModelReference modelRef=new ModelRef("java.util.Map");

                    Optional<ResolvedType> type = Optional.absent();
                    Parameter newParameter=new Parameter(
                        "newName",
                        "newDescription",
                        null,
                        true,
                        false,
                        null,
                        modelRef,
                        type,
                        null,
                        "body",
                        null,
                        false,
                        null,
                        null,
                        2147483647,
                        null,
                        LinkedListMultimap.create(),
                        new ArrayList<>()
                    );

                    parameters.add(newParameter);
                    Set<ResponseMessage> responseMessages = operation.getResponseMessages();
                    ModelReference responseModel = operation.getResponseModel();

                }
            }
        }


        String s = JSONObject.toJSONString(aDefault);

        return jsonObject;
    }
}
